<template>
  <div class="goods-hot">
    <h3>{{types[type]}}</h3>
    <!-- 商品区块 -->
    <home-goods v-for="(good,index) in data" :key="index" :goods="good"/>
  </div>
</template>
<script>
import { findHotGoods } from '@/api/goods'
import { ref, onMounted } from 'vue'
import HomeGoods from '@/views/Home/components/home-goods.vue'
import { useRoute } from 'vue-router'
export default {
  name: 'GoodsHot',
  components: {
    HomeGoods
  },
  props: {
    type: {
      type: String
      // default: 1
    }
  },
  setup (props) {
    const types = {
      1: '24小时热销榜',
      2: '周热销榜',
      3: '总热销榜'
    }
    const data = ref({})
    const route = useRoute()
    async function loadData () {
      const res = await findHotGoods({ id: route.params.id, type: props.type })
      data.value = res.result
    }
    onMounted(() => {
      loadData()
    })

    return {
      types,
      data
    }
  }
}
</script>
<style scoped lang="less">
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
}
</style>
